package com.base.components.database.mybatis.service;

import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.common.Mapper;

import java.io.Serializable;
import java.util.List;

/**
 * AbstractMybatisService
 * @author <a href="drakelee1221@gmail.com">LiGeng</a>
 * @version v1.0.0
 * @date 2019-01-22 13:59
 */
public abstract class AbstractMybatisService<T extends Serializable, M extends Mapper<T>> implements MybatisService<T>{

  @Autowired
  private M mapper;

  protected M getMapper(){
    return mapper;
  }

  @Override
  @Transactional(rollbackFor = Exception.class)
  public T insert(T record) {
    getMapper().insert(record);
    return record;
  }
  @Override
  @Transactional(rollbackFor = Exception.class)
  public T insertSelective(T record) {
    getMapper().insertSelective(record);
    return record;
  }
  @Override
  @Transactional(rollbackFor = Exception.class)
  public int deleteByPrimaryKey(Object key) {
    return getMapper().deleteByPrimaryKey(key);
  }
  @Override
  @Transactional(rollbackFor = Exception.class)
  public int delete(T record) {
    return getMapper().delete(record);
  }
  @Override
  @Transactional(rollbackFor = Exception.class)
  public int deleteByExample(Object example) {
    return getMapper().deleteByExample(example);
  }
  @Override
  @Transactional(rollbackFor = Exception.class)
  public int updateByPrimaryKey(T record) {
    return getMapper().updateByPrimaryKey(record);
  }
  @Override
  @Transactional(rollbackFor = Exception.class)
  public int updateByPrimaryKeySelective(T record) {
    return getMapper().updateByPrimaryKeySelective(record);
  }
  @Override
  @Transactional(rollbackFor = Exception.class)
  public int updateByExample(T record, Object example) {
    return getMapper().updateByExample(record, example);
  }
  @Override
  @Transactional(rollbackFor = Exception.class)
  public int updateByExampleSelective(T record, Object example) {
    return getMapper().updateByExampleSelective(record, example);
  }
  @Override
  public List<T> selectAll() {
    return getMapper().selectAll();
  }
  @Override
  public T selectByPrimaryKey(Object key) {
    return getMapper().selectByPrimaryKey(key);
  }
  @Override
  public int selectCount(T record) {
    return getMapper().selectCount(record);
  }
  @Override
  public List<T> select(T record) {
    return getMapper().select(record);
  }
  @Override
  public T selectOne(T record) {
    return getMapper().selectOne(record);
  }
  @Override
  public List<T> selectByExample(Object example) {
    return getMapper().selectByExample(example);
  }
  @Override
  public int selectCountByExample(Object example) {
    return getMapper().selectCountByExample(example);
  }
  @Override
  public T selectOneByExample(Object example) {
    return getMapper().selectOneByExample(example);
  }
  @Override
  public List<T> selectByExampleAndRowBounds(Object example, RowBounds rowBounds) {
    return getMapper().selectByExampleAndRowBounds(example, rowBounds);
  }
  @Override
  public List<T> selectByRowBounds(T record, RowBounds rowBounds) {
    return getMapper().selectByRowBounds(record, rowBounds);
  }
  @Override
  public boolean existsWithPrimaryKey(Object key) {
    return getMapper().existsWithPrimaryKey(key);
  }
}
